package com.mobilesalon.activity;

import java.util.List;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;

import com.mobilesalon.MobileSalonFactory;
import com.mobilesalon.R;
import com.mobilesalon.calendar.CalendarProvider;
import com.mobilesalon.calendar.PhoneCalendarBean;

public class SettingsActivity extends PreferenceActivity {

	//
	// Gui widgets
	//

	private ListPreference calendarListPreference;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);

		//
		// Fetch only google calendars
		//
		final CalendarProvider calendarProvider = MobileSalonFactory.getCalendarProvider();
		final List<PhoneCalendarBean> phoneCalendarBeans = calendarProvider.getPhoneCalendars();

		//
		// display calendars
		// 
		String[] phoneCalendarSrings = new String[phoneCalendarBeans.size()];
		String[] phoneCalendarIds = new String[phoneCalendarBeans.size()];
		
		for(int i = 0; i < phoneCalendarBeans.size();i++){
			phoneCalendarSrings[i] = phoneCalendarBeans.get(i).getName()+"\n"+phoneCalendarBeans.get(i).getAccountOwner();
			phoneCalendarIds[i] = String.valueOf(phoneCalendarBeans.get(i).getAccountOwner());
		}
		
		ListPreference listPreference = (ListPreference) findPreference("preference_list_calendar_selection");
		listPreference.setEntries(phoneCalendarSrings);
		listPreference.setEntryValues(phoneCalendarIds);
		listPreference.setNegativeButtonText(R.string.button_cancel);
		
		
	}
}
